<?php
// 获取留言的数据

$link = mysqli_connect("localhost","root","root","2113");

// 接收 传递过来的页码 ；1
$p = $_GET['p'];
// 如何通过页码 获取对应的数据？？？
// 1 ---- 0-5-----> LIMIT 0,5(Perpage)  ------> (p-1)*5 ,5
// 2 ----> 6-10  ---->LIMIT 5,5    -------> (p-1)*5,5
// 3 ---> 11- 15 ----> LIMIT 10,5  ----> (p-1)*5,5
// .....
$perPage = 5;
$start = ($p-1)*$perPage;

$sql = "SELECT * FROM message LIMIT $start,$perPage";
$list = getList($link,$sql);

foreach($list as $k=>$v){
	$id = $v['id'];
	// echo $id;
	// echo "<hr>";
	$sql = "SELECT * FROM relpay WHERE mid=$id";
	$replayArr = getList($link,$sql);
	// print_r($replayArr);
	// echo "<hr>";
	// $list[$k] == $v
	$list[$k]['replayList'] = $replayArr;
	// $v['replayList'] = $replayArr;
	
}

// echo "<pre>";
// print_r($list);
// echo "</pre>";
echo json_encode($list);


function getList($link,$sql){
	$res =  mysqli_query($link,$sql);
	$arr = [];
	while($one=mysqli_fetch_assoc($res)){
		$arr[] = $one;
	}
	return $arr;
}








?>